import * as React from 'react'
import { Link } from 'react-router-dom';
/**定义组件props */
export interface Props {
  name: string
  enthusiasmLevel?: number
  // onIncrement?: () => void
  // onDecrement?: () => void
}
// props是父组件传递进来的参数，react基础使用就不细说了
export default class Hello extends React.Component<Props, object> {
  render() {
    const { name, enthusiasmLevel = 1 } = this.props;

    if (enthusiasmLevel <= 0) {
      throw new Error('You could be a little more enthusiastic. :D');
    }

    return (
      <div className="hello">
        <Link to="/" replace>首页</Link>

        <div className="greeting">
          Hello组件 {name + getExclamationMarks(enthusiasmLevel)}
        </div>

        <Link to="/box" replace>box页面</Link>
      </div>
    );
  }
}

function getExclamationMarks(numChars: number) {
  return Array(numChars + 1).join('!');
}
